package com.amos.generate.service.impl;

import com.amos.generate.bean.*;
import com.amos.generate.service.AbstractColumnHandler;
import com.amos.generate.service.AbstractHandler;
import com.amos.generate.type.TemplateTypeEnum;
import com.amos.generate.util.VelocityUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Copyright © 2018 嘉源锐信. All rights reserved.
 *
 * @Project: mu-exam
 * @ClassName: MapperXmlHandler
 * @Package: com.amos.generate.service.impl
 * @author: zhuqb
 * @Description:
 * @date: 2020/3/12 0012 上午 11:57
 * @Version: V1.0
 */
public class MapperXmlHandler extends AbstractColumnHandler<MapperXmlField> {

    private String path;
    private String rootPackageName;
    private String tableName;
    private List<DataBaseField> list;

    public MapperXmlHandler(String path, String rootPackageName, String tableName,List<DataBaseField> list) {
        super(path, rootPackageName, tableName, TemplateTypeEnum.XML,false,list);
        this.path = path;
        this.rootPackageName = rootPackageName;
        this.tableName = tableName;
        this.list = list;
    }

    @Override
    protected Class<?> getFilterClass() {
        return null;
    }

    @Override
    public MapperXmlField getColumnList(List<DataBaseField> list) {
        MapperXmlField mapperXmlField = new MapperXmlField();
        List<XmlField> fields = new ArrayList<>(list.size());
        List<String> imports = new ArrayList<>();
        list.stream().forEach(item->{
            XmlField xmlField  = new XmlField();
            xmlField.setJavaField(VelocityUtils.underline2Camel(item.getColumnName()));
            xmlField.setJavaType(getJavaType(item));
            xmlField.setColumnName(item.getColumnName());
            fields.add(xmlField);
        });
        mapperXmlField.setColumns(fields);
        return mapperXmlField;
    }
}
